package com.example.demo.controller;


import com.example.demo.pojo.User;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

@RestController
public class UserController {

    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/user/{id}")
    public Optional<User> getUser(@PathVariable Long id) {
        System.out.println(id);
        System.out.println(userService.getUserById(id));;
        return userService.getUserById(id);
    }

    @GetMapping("/clear/{id}")
    public String clear(@PathVariable Long id){
        userService.clearCache(id);
        return "清除成功";
    }

    @GetMapping("/update")
    public String update(){
        User user = new User();
        user.setStuId(1L);
        user.setStuClass("1111");
        userService.updateUser(user);
        return "更新成功";
    }

}
